package com.esm.sm800.database.manager;

import com.esm.sm800.activity.AppContext;
import com.esm.sm800.database.dbmodel.Buzhen_report;
import com.esm.sm800.database.greendao.Buzhen_reportDao;

import java.util.ArrayList;

public class BuzhenreportCenter {

    private static BuzhenreportCenter instance = new BuzhenreportCenter();

    public static BuzhenreportCenter getInstance() {
        return instance;
    }

    public Buzhen_report getBuzhen_report(long nid) {
        Buzhen_report Buzhen_report = null;
        try {
            Buzhen_reportDao Buzhen_reportDao = AppContext.getInstances().getDaoSession().getBuzhen_reportDao();
            ArrayList<Buzhen_report> list = new ArrayList<Buzhen_report>();
            list = (ArrayList) Buzhen_reportDao.queryBuilder()
                    .where(com.esm.sm800.database.greendao.Buzhen_reportDao.Properties.Nid.eq(nid))
                    .build().list();
            if (list.size() > 0) {
                Buzhen_report = list.get(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return Buzhen_report;
    }

    public Long saveBuzhen_report(Buzhen_report Buzhen_report) {
        if (Buzhen_report == null) {
            return 0L;
        }

        try {
            Buzhen_reportDao Buzhen_reportDao = AppContext.getInstances().getDaoSession().getBuzhen_reportDao();
            long id = Buzhen_reportDao.insertOrReplace(Buzhen_report);
            return id;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return 0L;
    }

    public ArrayList<Buzhen_report> buzhen_reportlist = null;

    public ArrayList<Buzhen_report> getBuzhen_reportlist(String startdate, String enddate) {

        ArrayList<Buzhen_report> list = new ArrayList<Buzhen_report>();
        try {
            Buzhen_reportDao Buzhen_reportDao = AppContext.getInstances().getDaoSession().getBuzhen_reportDao();
            if (startdate.length() < 1 || enddate.length() < 1 || startdate.compareTo(enddate) > 0) {
                list = (ArrayList) Buzhen_reportDao.queryBuilder()
                        .orderDesc(com.esm.sm800.database.greendao.Buzhen_reportDao.Properties.Creat_time)
                        .build().list();
            } else {
                startdate += " 00:00:00";
                enddate += " 23:59:59";
                list = (ArrayList) Buzhen_reportDao.queryBuilder()
                        .where(com.esm.sm800.database.greendao.Buzhen_reportDao.Properties.Creat_time.ge(startdate))
                        .where(com.esm.sm800.database.greendao.Buzhen_reportDao.Properties.Creat_time.le(enddate))
                        .orderDesc(com.esm.sm800.database.greendao.Buzhen_reportDao.Properties.Creat_time)
                        .build().list();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }
}
